﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace CustomerOrderingSystem
{
    public partial class OrderStatus : Form
    {
        private string sql = "";
        
        public OrderStatus()
        {
            InitializeComponent();
        }
        private void OrderStatus_Load(object sender, EventArgs e)
        {
            ordersDataGridView.DataSource = sql_order.QueryDataTable0();
        }

        
        private void button2_Click_1(object sender, EventArgs e)
        {
            MakeSqlStr();
            ordersDataGridView.DataSource = sql_order.QueryDataTable(sql);
        }
        private void MakeSqlStr()
        {
            sql = "";
            if (onoTextBox.Text.Trim() != string.Empty)
            {
                sql = "and Ono ='" + onoTextBox.Text.Trim() + "'";
            }
            if (cnoTextBox.Text.Trim() != string.Empty)
            {
                sql += "and Cno ='" + cnoTextBox.Text.Trim() + "'";
            }
        }
        private void Update_Click_1(object sender, EventArgs e)
        {
            try
            {
                int cnt = sql_order.QueryDataTable1(onoTextBox1.Text);
                if (cnt == 1)
                {
                    MessageBox.Show("更新成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sql_order.QueryDataTable2(cnoTextBox1.Text, gnoTextBox.Text, gnumTextBox.Text, onoTextBox1.Text);
                }
                // 添加新记录
                else
                {
                    MessageBox.Show("添加成功！", "提示", MessageBoxButtons.OK);
                    sql_order.QueryDataTable3(onoTextBox1.Text, cnoTextBox1.Text, gnoTextBox.Text, gnumTextBox.Text);
                }
                OrderStatus_Load(null, null);
            }
            finally
            {
                sql_order.QueryDataTable4();
            }
       
        }

        private void Del_Click_1(object sender, EventArgs e)
        {
            DialogResult ret = MessageBox.Show("确定要删除记录吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (ret == DialogResult.Cancel)
            {
                return;
            }

            try
            {

                if (sql_order.QueryDataTable5(onoTextBox1.Text) == 1)
                {
                    MessageBox.Show("删除成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                OrderStatus_Load(null, null);
            }
            finally
            {
                sql_order.QueryDataTable4();
            }
        }

        private void cnoTextBox_TextChanged(object sender, EventArgs e)
        {

        }
    }

}